<?php
namespace app\send\logic\msg;
use app\send\logic\msg\Msg;
use \think\Config;
/**
 * 创盛短信
 */
class ChuangLaiMsg extends Msg
{
    /**
     * [发送验证码]
     * @param  [type] $phone [手机号]
     * @param  [type] $code  [验证码]
     * @return [type]        [description]
     */
	public function index($phone,$code){
        header("Content-Type:text/html;charset=utf-8");        
        vendor("send.Chuanglan.ChuanglanSmsApi");
        $config = Config::get('chuanglan');
        $account = $config['account'];
        $password = $config['password'];
        $clapi = new \ChuanglanSmsApi($account,$password);
        $sign = $config['sign'];
        $result = $clapi->sendSMS($phone,'【'.$sign.'】您好，您的验证码是'.$code.',若非本人操作请忽略此消息。');
        //halt($result);
        if(!is_null(json_decode($result))){
            $output=json_decode($result,true);
            if(isset($output['code'])  && $output['code']=='0'){
                return [
                    'code'=>1,
                ];
            }else{
                return [
                    'code'=>0,
                    'msg'=>$output['errorMsg']
               ];
            }
        }else{
            return [
                'code'=>0,
                'msg'=>'发送失败！'
           ];
        }
    }
    /**
     * [发送消息文本]
     * @return [type] [description]
     */
    public function info($phone,$content){
        vendor("send.Chuanglan.ChuanglanSmsApi");
        $account = 'N2433355';
        $password = 'L8KSMsjXD1c0c1Q';
        $clapi = new \ChuanglanSmsApi($account,$password);
        $sign = '马拉松报名网';
        //设置您要发送的内容：其中“【】”中括号为运营商签名符号，多签名内容前置添加提交
        $msg = '【'.$sign.'】'.$content;
        return true;
    }
    public function getHttp($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
     }
    
}

